<%@page contentType="text/html"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 

<%@ page import="javax.mail.internet.AddressException" %>
<%@ page import="javax.mail.MessagingException" %>
<%@ page import="java.io.IOException" %>

<%@ page import="org.adl.registry.website.mail.EmailMessage" %>
<%@ page import="org.adl.registry.website.ErrorHandler" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!--
* This software is licensed as open source software pursuant to the terms defined in the 
* Joint ADL Co-Lab Open Source Software License.  Use of any part of this software constitutes
* acceptance of this license. The Joint ADL Co-Lab open source agreement is available at 
* http://adlregistry.adlnet.gov/source_license.html.
-->

<%
boolean name_error = false;
boolean email_error = false;
boolean comment_error = false;

String from = "";
String name = "";
String comments = "";

// Check to see if the submission buttion is included in the request. If it is then it is assumed that the request is a postback.
String postback = request.getParameter("btnPost");             
%>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>ADL Registry</title>
        <%@ include file="/_common/document_head.jsp" %>
    </head>
    <body>
        <%@ include file="/_common/no_script.jsp" %>
        <div id="container">
            <%@ include file="/_common/header.jsp" %>
            
            <div id="nav_main">
                <ul>
                    <li id="nav_main_search"><a href="/search/index.jsp">Search</a></li>
                    <li id="nav_main_contribute"><a href="/contribute/index.jsp">Contribute</a></li>
                    <li id="nav_main_gettingstarted" class="active"><a href="/help/index.jsp">Getting Started</a></li>
                </ul>
            </div><!-- #nav_main -->
	
            <div id="nav_sub">
                <ul>
                    <li><a href="/register/index.jsp">Register Repository/Contributors</a></li>
                    <li><a href="/help/faq.jsp">FAQs</a></li>
                    <li><a href="/about/developers/index.jsp">Technical Reference</a></li>
                    <li><a href="/about/index.jsp">About ADL Registry</a></li>
                </ul>
            </div><!-- #nav_sub -->
	
            <div id="nav_breadcrumb">
                <ul>
                    <li><a href="/index.jsp">Home</a></li>
                    <li><a href="/help/index.jsp">Help</a></li>
                    <li class="last">Contact</li>
                </ul>
            </div><!-- #nav_breadcrumb -->
            
            <div id="content">
                <!-- Begin Page Content -->
                <h2>Contact The ADL Registry Support Team</h2>
                <p>
                    For questions about the ADL Registry please complete the form below. Questions submitted to The ADL Registry Support Team will, on average, recieve a response within five (5) business days. 
                </p>
                <%
                if (postback != null)
                {
                    from = request.getParameter("email_textbox");
                    name = request.getParameter("name_textbox");
                    comments = request.getParameter("comments_textbox");
                    
                    EmailMessage message = new EmailMessage();
                    
                    try
                    {
                        message.setSender(from);
                        message.getSender().validate();
                    }
                    catch (AddressException ex)
                    {
                        email_error = true;
                    }
                    
                    if (name.length() == 0)
                    {
                        name_error = true;
                    }
                    
                    if (comments.length() == 0)
                    {
                        comment_error = true;
                    }
                    
                    if ((comment_error == false) && (name_error == false) && (email_error == false))
                    {
                        message.setSubject("ADL Registry Website Support Request");
                        
                        message.addLineToBody("********************************");
                        message.addLineToBody("Submitter Information");
                        message.addLineToBody("********************************");
                        message.addLineToBody("");
                        message.addLineToBody("From: " + name);
                        message.addLineToBody("Email: " + from);
                        message.addLineToBody("");
                        message.addLineToBody("Comments:");
                        message.addLineToBody(comments);
                        
                        try
                        {
                            message.send(request);
                            
                            if (response.isCommitted())
                            {
                                // TODO: Handle committed state.
                            }
                            else
                            {
                                try
                                {
                                    response.sendRedirect("/help/contact/success.jsp");
                                }
                                catch (IOException ex)
                                {
                                    // Should never occur since committed state is being checked.
                                }
                            }
                        }
                        catch (MessagingException ex)
                        {
                            ErrorHandler.ProcessGeneralError(response, this.getServletContext(), ErrorHandler.MESSAGING_ERROR_131, ex);
                        }
                    }
                    else
                    {
                        out.print("<div style=\"color:Red;font-weight:bold;\">Unable to submit support request. Please review the form below and try submitting again.</div>");
                    }
                }
                %>
                <form enctype="application/x-www-form-urlencoded" method="post" action="/help/contact/index.jsp" id="contact_form">
                    <center>
                        <table border="0">
                            <tr>
                                <td><strong>Your Name:</strong></td>
                                <td><input type="text" id="name_textbox" name="name_textbox" value="<%= name %>" style="width:300px;" /></td>
                                <td><% if (name_error)
                                { out.print("<span style=\"color:Red;\"> * Required</span>");} %></td>
                            </tr>
                            <tr>
                                <td><strong>Email Address:</strong></td>
                                <td><input type="text" id="email_textbox" name="email_textbox" value="<%= from %>" style="width:300px;" /></td>
                                <td><% if (email_error)
                                { out.print("<span style=\"color:Red;\"> * Invalid</span>");} %></td>
                            </tr>
                            <tr>
                                <td valign="top"><strong>Comments:</strong></td>
                                <td valign="top"><textarea name="comments_textbox" id="comments_textbox" rows="10" cols="20" style="width:300px;"><%= comments %></textarea></td>
                                <td><% if (comment_error)
                                { out.print("<span style=\"color:Red;\"> * Required</span>");} %></td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td><input type="submit" id="btnPost" name="btnPost" value="Send Comments" /></td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                            </tr>
                        </table> 
                    </center>
                </form>
                <!-- End Page Content --> 
            </div>
        </div>
        <%@ include file="/_common/footer.jsp" %>
    </body>
</html>

